import { createLogger, format, transports } from "winston";
import "winston-daily-rotate-file";

const customFormat = format.combine(
  format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
  format.align(),
  format.printf((log) => `${log.level}:${[log.timestamp]}:${log.message}`),
);

const defaultOptions = {
  format: customFormat,
  datePattern: "YYYY-MM-DD",
  zippedArchive: true,
  maxSize: "10m",
  maxFiles: "14d",
};

export const logger = createLogger({
  format: customFormat,
  transports: [
    new transports.DailyRotateFile({
      filename: "logs/info-%DATE%.log",
      level: "info",
      ...defaultOptions,
    }),
    new transports.DailyRotateFile({
      filename: "logs/error-%DATE%.log",
      level: "error",
      ...defaultOptions,
    }),
  ],
});
